package com.zys.el.search.client;

import com.zys.el.user.api.UserApi;
import com.zys.el.user.po.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@FeignClient(name = "user-service", /*fallback = UserClient.UserClientFallback.class*/fallbackFactory = UserClient.UserClientFallbackFactory.class)
public interface UserClient extends UserApi {
    @Component
    @RequestMapping("/user-fallback")
    class UserClientFallback implements UserClient {
        private static final Logger LOGGER = LoggerFactory.getLogger(NoteClient.NoteClientFallback.class);

        @Override
        public User edit(Long id) {
            LOGGER.error("异常出现，进入fallback方法");
            return null;
        }
    }


    @Component
    @RequestMapping("/user-fallback-factory")
    class UserClientFallbackFactory implements FallbackFactory<UserClient> {


        Logger logger = LoggerFactory.getLogger(UserClientFallbackFactory.class);
        @Override
        public UserClient create(Throwable throwable) {
            throwable.printStackTrace();
            logger.error(throwable.getMessage());
            return new UserClient() {
                @Override
                public User edit(Long id) {
                    return null;
                }
            };
        }
    }
}


